from rest_framework import serializers

from goodsapp.models import *


class CateSer(serializers.ModelSerializer):
    class Meta:
        model = Cate
        fields = '__all__'


class GoodsSer(serializers.ModelSerializer):
    cate=CateSer()     # 序列化的嵌套,前提是必须有外键关联的表
    class Meta:
        model = Goods
        fields = '__all__'

class GoodsDetailSer(serializers.ModelSerializer):
    class Meta:
        model=Goods
        fields = ["id", "name", "pic", "price","unit"]

class GoodsListSer(serializers.ModelSerializer):
    class Meta:
        model = Goods
        fields = '__all__'
